<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('托盘条码信息列表')" />
</head>
<body class="gray-bg">
<div class="container-div">
    <div class="row">
        <div class="col-sm-12 search-collapse">
            <form id="formId">
                <div class="select-list">
                    <ul>
                        <li>
                            <label>托盘条码：</label>
                            <input type="text" name="trayCode"/>
                        </li>
                        <li>
                            <label>条码头：</label>
                            <input type="text" name="tHead"/>
                        </li>
                        <li>
                            <label>是否可用：</label>
                            <select name="isUsed">
                                <option value="">所有</option>
                                <option value="Y">可用</option>
                                <option value="N">不可用</option>
                            </select>
                        </li>
                        <li>
                            <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search('formId','bootstrap-table')"><i class="fa fa-search"></i>&nbsp;搜索</a>
                            <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset('formId','bootstrap-table')"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                        </li>
                    </ul>
                </div>
            </form>
        </div>

        <div class="btn-group-sm" id="toolbar" role="group">
            <a class="btn btn-success" onclick="$.operate.add()" shiro:hasPermission="bas:traycode:add">
                <i class="fa fa-plus"></i> 添加
            </a>
            <a class="btn btn-primary single disabled" onclick="$.operate.edit()" shiro:hasPermission="bas:traycode:edit">
                <i class="fa fa-edit"></i> 修改
            </a>
            <a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()" shiro:hasPermission="bas:traycode:remove">
                <i class="fa fa-remove"></i> 删除
            </a>
            <a class="btn btn-success"  onclick="printCode()" >
                <i class="fa fa-plus"></i> 打印条码
            </a>
            <!--<a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="bas:traycode:export">-->
            <!--<i class="fa fa-download"></i> 导出-->
            <!--</a>-->
        </div>
        <div class="col-sm-12 select-table table-bordered">
            <table id="bootstrap-table"></table>
        </div>
    </div>
</div>
<th:block th:include="include :: footer" />
<th:block th:include="include :: LodopFuncs_js"></th:block>
<script th:inline="javascript">
    var editFlag = [[${@permission.hasPermi('bas:traycode:edit')}]];
    var removeFlag = [[${@permission.hasPermi('bas:traycode:remove')}]];
    var useableDatas = [[${@dict.getType('useable')}]];
    var prefix = ctx + "bas/traycode";

    $(function() {
        var options = {
            url: prefix + "/list",
            createUrl: prefix + "/add",
            updateUrl: prefix + "/edit/{id}",
            removeUrl: prefix + "/remove",
            exportUrl: prefix + "/export",
            modalName: "托盘条码信息",
            search: false,
            clickToSelect: true,//是否启用点击选中行
            uniqueId:"id",//表主键(用于修改和删除)
            sortName:"id",//必加排序 sortOrder: "asc"默认
            columns: [
                {
                    halign: 'center',
                    align:'center',
                    checkbox: true
                },
                {
                    title: "序号",
                    halign: 'center',
                    align:'center',
                    width: 55,
                    formatter:function (value, row, index) {
                        //获取每页显示的数量
                        var pageSize = $('#bootstrap-table').bootstrapTable('getOptions').pageSize;
                        //获取当前是第几页
                        var pageNumber = $('#bootstrap-table').bootstrapTable('getOptions').pageNumber;
                        //返回序号，注意index是从0开始的，所以要加上1
                        return pageSize * (pageNumber - 1) + index + 1;

                    }
                },

                {
                    field: 'id',
                    title: 'id',
                    halign: 'center',
                    align:'center',
                    sortable: true,
                    visible: false
                },
                {
                    field: 'trayCode',
                    title: '托盘条码',
                    halign: 'center',
                    align:'center',
                    sortable: true,
                    visible: true
                },
                {
                    field: 'tHead',
                    title: '条码头',
                    halign: 'center',
                    align:'center',
                    sortable: true,
                    visible: true
                },
                {
                    field: 'isUsed',
                    title: '是否可用',
                    halign: 'center',
                    align:'center',
                    sortable: true,
                    visible: true,
                    formatter: function(value, row, index) {
                        return $.table.selectDictLabel(useableDatas, value);
                    }
                },
                // {
                //     title: '操作',
                //     halign: 'center',
                //     align: 'center',
                //     formatter: function(value, row, index) {
                //         var actions = [];
                //         actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.id + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                //         actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.id + '\')"><i class="fa fa-remove"></i>删除</a>');
                //         return actions.join('');
                //     }
                // }
            ]
        };
        $.table.init(options);
    });

    function printCode() {
        // LODOP.SET_LICENSES("","AF8A5800B838C952E0BCF67B9260DEA6","","");
        // alert("SET_LICENSES执行啦！！！")
        var checkedItems = $('#bootstrap-table').bootstrapTable('getSelections');
        var cishu = 2;//打印次数
        LODOP = getLodop(document.getElementById('LODOP_OB'), document
            .getElementById('LODOP_EM'));
        LODOP.SET_SHOW_MODE("LANGUAGE", 0);
        //LODOP.PRINT_INITA(20, 40, 2400, 1800, "托盘条码");
        LODOP.SET_PRINT_PAGESIZE(1, "100mm", "60mm", "");
        LODOP.SET_PRINT_MODE("POS_BASEON_PAPER",true);
        LODOP.SET_PRINT_MODE("AUTO_CLOSE_PREWINDOW", 1);//打印后自动关闭预览窗口(2019-1-30)
        LODOP.SET_PRINT_STYLE("FontSize", 12);
        //LODOP.SET_PRINT_STYLE("FontName", "方正粗黑");
        LODOP.SET_PRINT_STYLE("FontName", "Arial");
        LODOP.SET_PRINT_STYLE("Bold", 1);
        if (checkedItems.length == 0) {
            alert("请选择要打印的数据！");
            return;
        }
        if (checkedItems.length > 0) {
            $.each(checkedItems, function (index, item) {
                //alert(item.trayCode);
                LODOP.NewPage();
                LODOP.ADD_PRINT_TEXT(26, 110, 200, 200,item.trayCode);
                LODOP.ADD_PRINT_BARCODE(39, 130, 135, 135, "QRCode", item.trayCode);


                /////需要添加 将托盘的条码 的可用状态修改为已经使用
                //将条码的可用状态改为已经使用
                changeUsed(item.trayCode);
                $.table.search();
            });
        }
        //新建打印页面
        LODOP.PREVIEW();
    }

    function changeUsed(tra) {
        $.ajax({
            "url": "/bas/traycode/updateStatus?trayCode=" + tra,
            "type": "GET",
            "dataType": "json",
            "success": function (result) {
                console.log(result);
            }
        });
    }
</script>
</body>
</html>